package top.gcl.config;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import top.gcl.model.JsonResult;

//异常错误处理
@ControllerAdvice
public class GlobalExceptionHandler {
    //当Controller抛出Exception异常时，由该方法处理
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public JsonResult handlerException(Exception e) {
        JsonResult res=new JsonResult(500,"服务器发生错误！");
        return res;
    }
    //当Controller抛出RuntimeException异常时，由该方法处理
    //运行异常
    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public JsonResult handlerException() {
        JsonResult res=new JsonResult(600,"服务器错误！");
         return res;
    }
}
